<!-- 参数设置 -->
<template>
  <div class="container-app">
    <div class="bg-white">
      <div class="q-pa-sm">
        副井提升机参数设置
      </div>
      <q-separator />
      <div class="q-pa-md">
        <span>
          打油后长度
          <q-input
            outlined
            dense
            style="width: 200px; display: inline-block;"
            v-model="setList[0]['value']"
            class="q-px-sm"
            @update:model-value="setHealthScoreUp(0)"
          />
          <span>mm</span>
        </span>
      </div>
      <div class="q-pa-md">
        <span>
          振动极限值
          <q-input
            outlined
            dense
            style="width: 200px; display: inline-block;"
            v-model="setList[1]['value']"
            class="q-px-sm"
            @update:model-value="setHealthScoreUp(1)"
          />
          <span>mm/s</span>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import { fetchGlobalSetupList, setGlobalSetupInfo } from 'src/api/systemtWarning'
export default {
  name: 'ParamsSet',
  data () {
    return {
      changeDevOrAsset: 1,
      setList: [
        {
          data_type: '',
          data_type_string: null,
          data_unit: false,
          id: null,
          is_inform: false,
          name: 'distance_buyoil', // 打油后长度
          value: ''
        },
        {
          data_type_string: null,
          data_unit: false,
          id: null,
          is_inform: false,
          name: 'vibrate_threshold', // 振动极限值
          value: ''
        }
      ]
    };
  },

  components: {},

  computed: {},

  mounted() {
    this.getSystemWarnDetail({ name: 'distance_buyoil' })
    this.getSystemWarnDetail({ name: 'vibrate_threshold' })
  },

  methods: {
    getSystemWarnDetail(name) {
      fetchGlobalSetupList(name).then(res => {
        const setData = res.data
        if (setData.name === 'distance_buyoil') {
          this.setList[0] = setData
        }
        if (setData.name === 'vibrate_threshold') {
          this.setList[1] = setData
        }
      })
    },
    setCurrentWarningDetail(setQuery) {
      setGlobalSetupInfo(setQuery).then(res => {
        if (res.status === 200) {
          if (setQuery.name === 'distance_buyoil') {
            this.getSystemWarnDetail({ name: 'distance_buyoil' })
          } else {
            this.getSystemWarnDetail({ name: 'vibrate_threshold' })
          }
          this.$q.notify({
            position: 'top',
            message: '设置成功！',
            type: 'positive'
          })
        } else {
          this.$q.notify({
            position: 'top',
            message: res.msg,
            type: 'warning'
          })
        }
      })
    },
    // 设置健康值上限/下限/是否通知
    setHealthScoreUp(parmas) {
      let setQuery
      this.$forceUpdate()
      if (parmas === 0) {
        // setQuery = Object.assign({}, this.setList[0])
        setQuery = {
          name: 'distance_buyoil',
          value: this.setList[0].value
        }
        this.setCurrentWarningDetail(setQuery)
        return
      }
      // setQuery = Object.assign({}, this.setList[1])
      setQuery = {
        name: 'vibrate_threshold',
        value: this.setList[1].value
      }
      this.setCurrentWarningDetail(setQuery)
    }
  }
}

</script>
<style lang='scss' scoped>
</style>
